import type Yoga from 'yoga-layout'

// 缓存 Yoga 模块，避免重复加载
let yogaModule: typeof Yoga | null = null

// 动态加载 Yoga Layout
export function loadYoga(): Promise<typeof Yoga> {
  if (yogaModule) return Promise.resolve(yogaModule)
  return import('yoga-layout')
    .then((module) => {
      yogaModule = module.default
      console.log('Yoga 加载成功')
      return yogaModule
    })
    .catch((error) => {
      console.error('Yoga 加载失败:', error)
      throw error
    })
}

